#include<GL/glut.h>
int win_w=480;
int win_h=272;
double mx,my;
float plist[1024][3];
double slist[1024][3];
int pcur=0;
int circle=4;
GLfloat cplist[1024][3] = { 
		{ -4.0, -4.0, 0.0}, { -2.0, 4.0, 0.0},
		{2.0, -4.0, 0.0}, {4.0, 4.0, 0.0}};
void mkslist(){
	int i,j;
	for(i=0;i<pcur;i++)
		for(j=0;j<3;j++)
			cplist[i][j]=plist[i][j];
}
void display()
{
	int i,j;
    glClear(GL_COLOR_BUFFER_BIT);
	glBegin(GL_LINE_STRIP);
//	glBegin(GL_POINTS);
	glTranslatef(-3,0,0);	
	for(i=0;i<pcur;i++)
		glVertex3f(plist[i][0],plist[i][1],0);
	glEnd();
	if(pcur>=400)
	{
			for(j=0;j<=pcur-3;j++)
			{
			glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 5,&plist[j][0]);
			glBegin(GL_LINE_STRIP);
			for(i=0;i<30;i++)
			glEvalCoord1f((GLfloat) i/30.0);
			glEnd();
			}
	}
   	glutSwapBuffers();
}
void init(void)
{
		glEnable(GL_MAP1_VERTEX_3);
		glShadeModel(GL_FLAT);
}
void mouse(int button,int state,int mousex,int mousey)
{
		plist[pcur][1]=7.07-mousex/(win_w*1.0)*14.1;
		plist[pcur][0]=-6.5+mousey/(win_h*1.0)*13.3;
		plist[pcur][2]=0.0;
		pcur++;
		mkslist();
        glutPostRedisplay(); 
}
void keyboard(unsigned char key, int x, int y)
{
        //glutPostRedisplay(); 
}
void reshape(int w,int h)
{
		/* define the pojection mode and view port*/
		glViewport(0,0,w,h);
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	gluPerspective(45.0,1.0,1.0,45.0);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    	gluLookAt(0.,0.0,-15,0.0,0.0,0.0,-1.0,0.0,0.0);
}
int main(int argc,char** argv)
{
		/* platform dependency */
		glutInit(&argc,argv);
		glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
		glutInitWindowSize(win_w,win_h);
		glutInitWindowPosition(200,200);
		glutCreateWindow("painting");
		/* global rendering initial*/
		init();
		/* */
		glutDisplayFunc(display);		
       	glutKeyboardFunc(keyboard);
		glutReshapeFunc(reshape);
		glutMouseFunc(mouse);
		/* full screen option
		 * variation: enable fullscreen display V1*/
//		glutFullScreen();//V1
		glutMainLoop();
}
